package com.zyf.pattern.observer.subject;

import com.zyf.pattern.observer.core.Event;

import java.lang.reflect.Method;

/**
 * create by yifeng
 */
public class ObserverTest {
    public static void main(String[] args) {
        try {
            // 观察者
            ObServer obServer = new ObServer();
            Method advice = ObServer.class.getMethod("advice", new Class<?>[]{Event.class});


            // 被观察者
            Subject subject =new Subject();
            subject.addLisenter(SubjectEventType.ON_ADD, obServer, advice);
            subject.addLisenter(SubjectEventType.ON_EDIT, obServer, advice);
            subject.addLisenter(SubjectEventType.ON_QUERY, obServer, advice);
            subject.addLisenter(SubjectEventType.ON_REMOVE, obServer, advice);
            subject.add();
            subject.remove();

        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
